<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/10
 * Time: 15:26
 */

namespace common\business\task;


use common\models\Task;
use yii\base\Model;

class TaskRequestData extends Model
{
    /** 任务类型
     * @var string
     */
    public $type;
    /** 任务key
     * @var string
     */
    public $key;
    /** 任务系统
     * @var string
     */
    public $from_system;

    /**
     * @var string
     */
    public $data;

    /**
     * TaskRequestData constructor.
     * @param string $type
     * @param string $key
     * @param string $from_system
     * @param string $data
     */
    public function __construct($type, $key, $from_system, $data)
    {
        parent::__construct([
            'type' => $type,
            'key' => $key,
            'from_system' => $from_system,
            'data' => $data,
        ]);
    }

    public function buildFromStr($string){
        $this->setAttributes(json_decode($string, true));
    }

    /**
     * @param $task Task
     */
    public static function buildFromTask($task){
        $newRequestData = new TaskRequestData($task->type, $task->key, $task->from_system, $task->request_data);
        return $newRequestData;
    }
}